#!/usr/bin/env bash

BASEDIR=$(cd `dirname $0`; pwd)

ANTARES_HOME=$BASEDIR/..

LIB_HOME=$ANTARES_HOME/lib

CONF_FILE=$ANTARES_HOME/conf/antares.conf
. $CONF_FILE

JAR_FILE=$LIB_HOME/genius-manager-server.jar

# JAVA_OPTS
JAVA_OPTS="-server -Duser.dir=$BASEDIR"

# CONFIG_OPTS
CONFIG_OPTS="--server.port=$LISTEN_PORT --spring.profiles.active=$SPRING_PROFILE"

function start()
{
    java $JAVA_OPTS -jar $JAR_FILE $CONFIG_OPTS $1 > /dev/null 2>&1 &
}

function stop()
{
    pid=$(ps aux |grep "${JAR_FILE}"|grep -v "grep"|awk '{print $2}')
    echo "kill $pid ..."
    kill $pid
}

args=($@)

case "$1" in

    'start')
        start
        ;;

    'stop')
        stop
        ;;

    'restart')
        stop
        start
        ;;

    'help')
        help $2
        ;;
    *)
        echo "Usage: $0 { start | stop | restart | help }"
        exit 1
        ;;
esac